<template>
  <div class="version-box">
<!--    <el-tag v-if="LicenseInfo.version">{{ LicenseInfo.version }}</el-tag>-->
    <el-tag class="mg-l-sm" type="success" v-if="LicenseInfo.running && LicenseInfo.version">运行中</el-tag>
    <el-tag class="mg-l-sm" type="danger" v-if="!LicenseInfo.running && LicenseInfo.version">未运行</el-tag>
  </div>
</template>

<script setup lang="ts">
import { nextTick, onMounted, ref } from "vue";
import { useUserStore } from "@/stores/modules/user";
import { cfg_softcheck, licenseList } from "@/api/modules/system/params";
import { cfgAppstate } from "@/api/modules/home";

const LicenseInfo = ref({
  license: "",
  version: "",
  isLicence: false,
  running: false
});

async function getCfg() {
  if (!useUserStore().userInfo.name) return;
  const res1 = await licenseList();
  const res2 = await cfgAppstate();
  const res3 = await cfg_softcheck();
  console.log("res2=============", res2);
  // useUserStore.setLicenseInfo({
  //   isLicence: res1.result.data && res1.result.data.length,
  //   license: res1.result.data[0][1] == 1 ? "测试版" : "正式版"
  // });
  localStorage.setItem(
    "LicenseInfo",
    JSON.stringify({
      isLicence: Boolean(res1.result.data && res1.result.data.length),
      license: res1.result.data[0][1],
      version: res3.version,
      licenseTime: res1.result.data[0][6],
      day: res1.result.data[0][4],
      running: res2.code > 0
    })
  );
  LicenseInfo.value = {
    isLicence: Boolean(res1.result.data && res1.result.data.length),
    license: res1.result.data[0][1],
    version: res3.version,
    licenseTime: res1.result.data[0][6],
    day: res1.result.data[0][4],
    running: res2.code > 0
  };
}

setTimeout(() => {
  getCfg();
}, 2000);
</script>

<style scoped>
.version-box {
  position: fixed;
  bottom: 10px;
  right: 10px;
}
</style>
